//
//  HNSH_HomeManagerTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/25.
//

#import "HNSH_HomeManagerTopView.h"
#import "SDCycleScrollView.h"

@interface HNSH_HomeManagerTopView ()<SDCycleScrollViewDelegate>
/* cycleScrollView */
@property(nonatomic, strong) SDCycleScrollView *cycleScrollView;

@end

@implementation HNSH_HomeManagerTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)setBanners:(NSArray *)banners {
    _banners = banners;
    NSMutableArray *ary = [NSMutableArray arrayWithCapacity:0];
    for (HNSH_HomeViewBannerItem *item in banners) {
        [ary addObject:item.image_url];
    }
    self.cycleScrollView.imageURLStringsGroup = ary;
    [self.cycleScrollView reloadInputViews];
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    HNSH_HomeViewBannerItem *item = self.banners[index];
    [NSString jumpToolsWithJumpType:item.jump_type jump_name:item.name jump_content:item.jump_content jump_params:item.jump_params];
}

- (void)configUI {
    [self addSubview:self.cycleScrollView];
    self.cycleScrollView.layer.cornerRadius = 8.0f;
    self.cycleScrollView.layer.masksToBounds = YES;
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(118);
    }];
}

#pragma mark lazy
//MARK: Getter Methods
- (SDCycleScrollView *)cycleScrollView{
    if (!_cycleScrollView) {
        _cycleScrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectZero];
        _cycleScrollView.delegate = self;
        _cycleScrollView.placeholderImage = [UIImage imageNamed:@"icon_place"];
        _cycleScrollView.autoScrollTimeInterval = 3.0;
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
        _cycleScrollView.titleLabelBackgroundColor = [UIColor clearColor];
        _cycleScrollView.backgroundColor = [UIColor appBGColor];
    }
    return _cycleScrollView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
